<template>
  <div class="form-elements">
    <div class="row">
      <div class="flex xs12">
        <va-card :title="'编辑入住信息'">
          <form>
            <div class="row">
              <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="date"
                  type="date"
                  :label="'日期'"
                />
              </div>
             <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="time"
                  type="time"
                  :label="'时间'"
                />
              </div>
            </div>
            <div class="row">
                           <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="roomNum"
                  type="text"
                  :label="'房间号'"
                />
              </div>
                           <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="peoples"
                  type="number"
                   min="0"
                   max="10"
                  :label="'人数'"
                />
              </div>


            </div>
            <div class="row">
                            <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="userRealname"
                  type="text"
                  :label="'入住人姓名'"
                />
              </div>
                            <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="userIdcard"
                  type="text"
                  :label="'入住人身份证'"
                />
              </div>
            </div>
            <div class="row">
                            <div class="flex md3 sm6 xs12">
                <va-input
                  v-model="remark"
                  type="text"
                  :label="'备注'"
                />
              </div>
            </div>
            <div class="row">
              <va-button @click="subadd">提交</va-button>
              <va-button @click="back">返回</va-button>
            </div>
          </form>
        </va-card>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'form-elements',
  data () {
    return {
      time:'',
      date:'',
      peoples:0,
      roomNum:'',
      userRealname:'',
      userIdcard:'',
      remark:'',
    }
  },
  created(){
    if(!this.$route.params.id)
       this.$router.push({ name: 'dashboard' })


    var cidata=JSON.parse(JSON.stringify(this.$route.params))
    console.log(this.$route.params)

  if(cidata.inTime!=null)
  {
    this.date=cidata.inTime.split(" ")[0]
    this.time=cidata.inTime.split(" ")[1]
  }

    this.peoples=cidata.peoples
    this.roomNum=cidata.roomNum
    this.userRealname=cidata.userRealname
    this.userIdcard=cidata.userIdcard
    this.remark=cidata.remark

  },
  methods: {
    subadd () {
      if(this.userRealname==''){
        this.showmsg('入住人姓名为空')
        return
      }
      var _this=this
      var fd = new URLSearchParams()
      fd.append('id',this.$route.params.id)
      if(this.date!=""){
        let dt=new Date(this.date+' '+this.time)
        fd.append('inTime',dt.toString())
      }
      fd.append('operatorId',this.$route.params.operatorId)
      fd.append('peoples',this.peoples)
      fd.append('remark',this.remark)
      fd.append('roomNum',this.roomNum)
      fd.append('userIdcard',this.userIdcard)
      fd.append('userRealname',this.userRealname)
      this.$http.post('http://8.135.35.123:9000/hotelsystem/checkin/mod',fd)
      .then(function(response) {
        if(response.data.code==80200) {
        _this.showmsg('修改成功')
        _this.$router.push({ name: 'checkin-list' })
        }
        else
          _this.showmsg('修改失败')
        },
        function(err){
          console.log(err)
        }
      )

    },
    back(){
        this.$router.push({ name: 'checkin-list' })
    },
    showmsg(msg) {
    this.showToast(
        msg,{
          position: 'top-center',
          duration: 2500,
          fullWidth: false,
        },
      )

    }
  },
}
</script>

<style>
  .row.row-inside {
    max-width: none;
  }
</style>
